local rootElement = getRootElement()
local screenWidth, screenHeight = guiGetScreenSize() -- Get the screen resolution

function onDamage ( attacker, weapon, bodypart, loss )
	--setElementData(source,"health",getElementData(getLocalPlayer(),"health")-loss)
	--odrzucaj(attacker, weapon, bodypart)
	--[[if getElementData(getLocalPlayer(),"health") > 100 then
		cancelEvent() --cancel the event
	end]]
end

addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), onDamage )

--Odrzucanie
--[[

function PobierzPozycjeKamery( x,y,z,obrot ,dystans )	
    obrot = obrot/180*3.14159265358979
    x = x - ( math.sin(obrot) * dystans )
    y = y + ( math.cos(obrot) * dystans )
	return x, y, z
end

function odrzucaj ( attacker, weapon, bodypart )
	if ( attacker ~= nil ) and (attacker ~= getLocalPlayer()) then 
		local x,y,z = getElementPosition(getLocalPlayer())
		local x1,y1,z1 = getElementPosition(attacker)
		local dis = (getDistanceBetweenPoints2D ( x,y, x1,y1 ))/5
		local pRot = getPedRotation(getLocalPlayer())
		local vx,vy,vz = PobierzPozycjeKamery( x1,y1,z1,pRot ,0.15 )
		 vx=x1-vx vy=y1-vy vz=(z1-vz)+0.125
		 setElementPosition(getLocalPlayer(),x,y,z+0.005)
		 --setElementVelocity(getLocalPlayer(),vx/dis,vy/dis,vz/dis)
		 setElementVelocity(getLocalPlayer(),vx/dis,vy/dis,0.005)
	end
end]]
--Wyswietlanie hp

--[[ 
 
function createText ( )
    if getElementData(getLocalPlayer(),"health") ~= false then
	local dxtext = string.format("%.0f",getElementData(getLocalPlayer(),"health"))
	dxDrawText("Health: "..dxtext, 44, screenHeight-80, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.02, "pricedown" )    -- Draw text shadow.
    dxDrawText("Health: "..dxtext, 44, screenHeight-80, screenWidth, screenHeight, tocolor ( 100, 255, 100, 255 ), 1, "pricedown" ) -- Draw text.
end
end
 
addEventHandler("onClientRender",rootElement, createText) -- keep the text visible with onClientRender.
]]
--SKIN REPLACEMENTS
function startskiny(res)
if res == getThisResource() then
setTimer(skiny,124,1)
setWeather ( 9 )
setTime ( 23, 00 )
end
end
function skiny ()
	outputDebugString("Loading skins")
	local skin = engineLoadTXD ( "skins/69.txd" ) --bleedin eyes in denim by Capitanazop
	engineImportTXD ( skin, 69 )
	local skin = engineLoadTXD ( "skins/70.txd" ) --ultra gory scientist by 50p
	engineImportTXD ( skin, 70 )
	local skin = engineLoadTXD ( "skins/127.txd" ) --flyboy from dawn of the dead by Slothman
	engineImportTXD ( skin, 127 )
	local skin = engineLoadTXD ( "skins/162.txd" ) --shirtless redneck by Slothman
	engineImportTXD ( skin, 162 )
	local skin = engineLoadTXD ( "skins/167.txd" ) --dead chickenman by 50p
	engineImportTXD ( skin, 167 )
	local skin = engineLoadTXD ( "skins/209.txd" ) --Noodle vendor by 50p
	engineImportTXD ( skin, 209 )
	local skin = engineLoadTXD ( "skins/230.txd" ) --will work for brains hobo by Slothman
	engineImportTXD ( skin, 230 )
	local skin = engineLoadTXD ( "skins/258.txd" ) --bloody sided suburbanite by Slothman
	engineImportTXD ( skin, 258 )
	local skin = engineLoadTXD ( "skins/264.txd" ) --scary clown by 50p
	engineImportTXD ( skin, 264 )
end
addEventHandler("onClientResourceStart", getRootElement(), startskiny)
--##Skiny koniec
--## Sounds

function grajSound(sound)
	local sound = playSound("sounds/"..sound, false)
end
addEvent("grajSound",true)
addEventHandler("grajSound",getRootElement(),grajSound)

function grajSoundElement(sound,element,loop)
	x,y,z = getElementPosition(element)
	local sound = playSound3D("sounds/"..sound,x,y,z,loop)
	setTimer(setElementPosition,100,getSoundLength(sound)/100,sound,getElementPosition(element))
end
addEvent("grajSoundElement",true)
addEventHandler("grajSoundElement",getRootElement(),grajSoundElement)

--## /Sounds

function humansWinlogo ( )
   		polowascreen = screenHeight/2
		dxDrawText("HUMANS SURVIVE ATTACK", screenWidth/20, screenHeight-polowascreen, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 2.55, "pricedown" )    -- Draw text shadow.
		dxDrawText("HUMANS SURVIVE ATTACK", screenWidth/20, screenHeight-polowascreen, screenWidth, screenHeight, tocolor ( 0, 255, 0, 255 ), 2.50, "pricedown" ) -- Draw text.
end

function zombiesWinlogo ( )
   		polowascreen = screenHeight/2
		dxDrawText("ZOMBIES TAKE OVER WORLD!", screenWidth/20, screenHeight-polowascreen, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 2.55, "pricedown" )    -- Draw text shadow.
		dxDrawText("ZOMBIES TAKE OVER WORLD!", screenWidth/20, screenHeight-polowascreen, screenWidth, screenHeight, tocolor ( 255, 0, 0, 255 ), 2.50, "pricedown" ) -- Draw text.
end


function pokazLogo (logo) 
	if logo == 1 then
		addEventHandler("onClientRender",rootElement, zombiesWinlogo)
		setTimer(wywalLogo,2500,1,2)
	elseif logo == 2 then
		addEventHandler("onClientRender",rootElement, humansWinlogo)
		setTimer(wywalLogo,2500,1,1) 
	end
end

function wywalLogo (logo)
if logo == 2 then
removeEventHandler("onClientRender", rootElement, zombiesWinlogo)
elseif logo == 1 then
removeEventHandler("onClientRender", rootElement, humansWinlogo)
end
end

addEvent("pokazWinLogo",true)
addEventHandler("pokazWinLogo",getRootElement(),pokazLogo)